import requests


class IhrmEmpApi(object):
    # 添加员工
    @classmethod
    def add_emp(cls, req_header, req_data):
        resp_add = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
                                 headers=req_header, json=req_data)
        return resp_add

    # 查询员工
    def query_emp(self, emp_id, req_header):
        resp_query = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                                  headers=req_header)
        return resp_query

    # 修改员工
    def modify_emp(self, emp_id, req_header, req_data):
        resp_modify = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                                   headers=req_header, json=req_data)
        return resp_modify

    # 删除员工
    def del_emp(self, emp_id, req_header):
        resp_del = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                                   headers=req_header)
        return resp_del


if __name__ == '__main__':
    headers = {"Authorization": "Bearer a28348fa-e1f0-4a4f-901d-7916e9b36a82"}
    req_data = {
        "username": "zs4",
        "mobile": "13874789401",
        "workNumber": "9527"
    }
    res = IhrmEmpApi.add_emp(headers, req_data)
    print("添加：", res.json())
